<template>
	<view>
		<u-cell-group title="基本信息">
			<u-cell-item title="账户名" :arrow="false">
				<u-input type="text" v-model="accountName" placeholder="输入账户名" input-align="right" height="80" />
			</u-cell-item>
			<u-cell-item title="卡号" :arrow="false">
				<u-input type="text" v-model="tailNo" placeholder="输入卡号后四位" input-align="right" height="80" />
			</u-cell-item>
			<u-cell-item title="当前欠款" :arrow="false">
				<b-number-input v-model="balance" slot="right-icon"></b-number-input>
			</u-cell-item>
		</u-cell-group>

		<u-cell-group title="固定信息">
			<u-cell-item title="信用额度" :arrow="false">
				<b-number-input v-model="limits" slot="right-icon"></b-number-input>
			</u-cell-item>
			<u-cell-item title="账单日">
				<b-select :list="billDayList" @confirm="billConfirm" :title="billDayTitle" slot="right-icon"></b-select>
			</u-cell-item>
			<u-cell-item title="还款日">
				<b-select :list="repayDayList" @confirm="repaymentConfirm" :title="repayDayTitle" slot="right-icon">
				</b-select>
			</u-cell-item>
		</u-cell-group>

		<u-cell-group title="账户设置">
			<u-cell-item title="计入净资产" :arrow="false">
				<u-switch v-model="enableToNetAssets"></u-switch>
			</u-cell-item>
			<u-cell-item title="隐藏账户" :arrow="false">
				<u-switch v-model="hidden"></u-switch>
			</u-cell-item>
			<u-cell-item title="高级功能" @click="click">
			</u-cell-item>

		</u-cell-group>

		<view class="u-m-t-10 button-box">
			<u-button type="warning" @click="save">保存</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				accountName: '',
				tailNo: '',
				balance: 0,

				limits: 50000,

				billDay: 1,
				billDayTitle: '每月1号',
				billDayList: [],

				repayDay: 1,
				repayDayTitle: '每月1号',
				repayDayList: [],

				enableToNetAssets: true,
				hidden: false,

				bank: {
					"name": ""
				},
				creditAdv: {
					"repayAlert": 1,
					"repayType": 1,
					"repayStartType": false
				}


			}
		},
		onShow() {
			uni.$once('credit_adv', (data) => {
				this.creditAdv = data
			})
		},
		onLoad(query) {

			let bank = this.$api.getBank(query.bankId);
			if (bank) {
				this.bank = bank;
				
				if(!this.accountName){
					this.accountName = this.bank.name + "信用卡";
				}
			}

			let dayList = this.$api.getConfDayList();
			this.billDayList = dayList;
			this.repayDayList = dayList;

		},
		methods: {
			billConfirm(e) {
				this.billDayTitle = e[0].label;
				this.billDay = e[0].value;
			},
			repaymentConfirm(e) {
				this.repayDayTitle = e[0].label;
				this.repayDay = e[0].value;
			},
			click() {
				uni.navigateTo({
					url: "credit_adv_settings"
				})
			},
			save() {
				let account = {
					"accountName": this.accountName,
					"accountType": 1,
					"iconUrl": this.bank.iconUrl,
					"bankId": this.bank.bankId,
					"tailNo": this.tailNo,
					"balance": this.balance,
					"limits": this.limits,
					"billDay": this.billDay,
					"repayDay": this.repayDay,
					"enableToNetAssets": this.enableToNetAssets,
					"hidden": this.hidden,
					"repayAlert": this.creditAdv.repayAlert,
					"repayType": this.creditAdv.repayType,
					"repayStartType": this.creditAdv.repayStartType
				};
				
				this.$api.addAccount(account).then((res)=>{
					console.log(res)
				});
			}
		}
	}
</script>

<style lang="scss">
	.button-box {
		padding: 30rpx;
	}
</style>
